Variable-length decoding apparatus and decoding method

ABSTRACT

Encoded data using reversible variable length code words is input to a forward decoder ( 123 ) to be decoded in the forward direction. When an error is detected in the encoded data in the forward decode processing, backward decode processing is started by a backward decoder ( 126 ). A decode value determination unit ( 125 ) determines a decode value by using the forward and backward decode results and the error detection positions in the encoded data in units of bits and syntax which are respectively detected in the forward decoding and the backward decoding.

The present application is a continuation of U.S. application Ser. No.09/319,160, filed Jun. 2, 1999, the entire contents of which areincorporated herein by reference.

TECHNICAL FIELD

The present invention relates to a variable-length decoding apparatusfor decoding encoded data formed from a variable length code used forcompression encoding of, e.g., a video signal, and a decoding method.

BACKGROUND ART

A variable length code is a code system for generating a code having ashort average code length by respectively assigning a code having ashort code length to a frequently occurring symbol and a code having along code length to a rarely occurring symbol on the basis of thefrequencies of occurrence of symbols. By using variable length codes,therefore, the amount of data can be greatly compressed as compared withthe data before encoding. For this reason, variable length codes arewidely used as codes for information compression.

In a video encoding system as well, variable length codes are used for ageneral standard scheme such as MPEG1, MPEG2, H.261, or H.263.

A general problem associated with variable length codes is that when anerror is mixed in encoded data due to a channel error or the like, theencoded data mixed with the error cannot be properly decoded by adecoding apparatus owing to the influences of the error. In order toprevent this problem, when an error can occur in a transmission channel,a method of preventing the propagation of an error by inserting synccodes in data at given intervals is generally used. A bit pattern thatdoes not appear by any combination of variable length codes is assignedto a sync code. According to this method, even if an error occurs inencoded data and the data cannot be decoded, the propagation of theerror can be prevented by resuming decoding upon detection of the nextsync code, thereby continuing the decoding.

Even with the use of sync codes, however, decoding cannot be performedfor encoded data between the position where an error has occurred anddecoding cannot be performed and the position where the next sync codeis detected.

A variable-length decoding/encoding apparatus which can reduce theportion, which cannot be decoded, by using variable length codes thatcan be decoded bidirectionally, i.e, forward and backward and performingbackward decoding upon detection of a next sync code, has been proposedin the patent application (Japanese Patent Application Nos. 7-260383 and9-81614) filed by the present applicant.

Even with such a variable-length encoding/decoding apparatus, an errorin encoded data can be detected only when, for example, a bit patternthat is not used as a code word of a variable-length code appears. Forthis reason, in some case, an error is detected at a succeeding positionconsiderably away from the position where the error is actually mixed inthe data. This is because a bit pattern that is not used as a code wordof a variable length code does not always appear at the position wherethe error is actually mixed in the data, and decode processing iscontinuously performed as long as a corresponding portion is present inthe bit patterns used as the code words of the variable length code. Asa result, an incorrect word code is erroneously decoded as a correctcode word.

Various methods have been examined as counter-measures against channelerrors in a video encoding/decoding apparatus. For example, severalmethods as countermeasures against channel errors are disclosed in aliterature (Hideo Kuroda, “Image Coding Technique”, Shokodo, 1996). Ofthese methods, error concealment is introduced as a technique used onthe decoder side. Error concealment is a technique of minimizing theinfluences of an error on a frame by using motion vectors on theperipheral portion of the frame upon occurrence of a loss of encodeddata.

If, however, an incorrect code word is decoded as a correct code word, atechnique of minimizing the influences of an error, such as the aboveerror concealment, cannot be used. As a result, the frame is affected bythe error.

The influences of an error in the INTRA mode (intraframe encoding mode)are larger than those in the INTER mode (interframe encoding mode), anda block in unnatural color appears on a frame.

As described above, in the conventional variable-length decodingapparatus, when a variable length code is decoded, an incorrect codeword may be decoded as a correct word. If, therefore, this apparatus isapplied to decoding of a variable length encoded video signal, a frameis affected by an error.

It is an object of the present invention to provide a variable-lengthdecoding apparatus and a decoding method which can decrease thepossibility that an incorrect code word is erroneously decoded as acorrect word, and can realize sufficient resistance to errors.

DISCLOSURE OF INVENTION

According to the present invention, there is provided a variable-lengthdecoding apparatus comprising an input unit for receiving encoded dataformed from a variable length code made up of code words that can bedecoded in both a forward direction and a backward direction, a forwarddecoder for decoding the encoded data in the forward direction, abackward decoder for decoding the encoded data in the backwarddirection, and a decode value determination unit for outputting a finaldecode result from decode results respectively obtained by the forwarddecoder and the backward decoder, wherein each of the forward andbackward decoders includes a detection unit for detecting an error inthe encoded data, and the decode value determination unit determines adecode value by using error detection positions in the encoded data inunits of bits and syntax, which are detected by the forward decoder andindicate an error position in the encoded data, and error detectionpositions in the encoded data in units of bits and syntax, which aredetected by the backward decoder and indicate an error position in theencoded data.

In this variable-length decoding apparatus, when errors are detected bythe forward and backward decoders, the decode value determination unitis notified of the error detection positions as two types of positioninformation, i.e., positions in units of bits and positions in units ofsyntax. The true error position can therefore be checked doubly on thebasis of the error detection positions in units of bits and the errordetection positions in units of syntax. This allows the use of onlydecode results corresponding to correct code words with a considerablyhigh probability, and hence can decreases the possibility of erroneouslydecoding an incorrect code word as a correct code word.

In addition, the decode value determination unit preferably uses adecode value determination method of,

(a) using a forward decode result as a decode value for code words up toa position a predetermined amount before the error detection position inunits of bit or syntax, which is obtained by the forward decoder, and abackward decode result as a decode value for code words from a positiona predetermined amount after the error detection position in units ofbits or syntax, which is obtained by the backward decoder, anddiscarding the remaining encoded data, when the error detectionpositions obtained by the forward and backward decoders do not crosseach other in units of both bits and syntax,

(b) using a forward decode result as a decode value for code words up toa position immediately before the error detection position in units ofsyntax, which is obtained by the backward decoder, and a backward decoderesult as a decode value for code words from a position immediatelyafter the error detection position in units of syntax, which is obtainedby the forward decoder, and discarding encoded data of a portion onwhich the error detection positions in units of syntax cross each other,when the error detection positions obtained by the forward and backwarddecoders do not cross each other in units of bits but cross each otherin units of syntax,

(c) using a forward decode result as a decode value for code words up toa position immediately before the error detection position in units ofbits, which is obtained by the backward decoder, and a backward decoderesult as a decode value for code words from a position immediatelyafter the error detection position in units of bits, which is obtainedby the forward decoder, and discarding encoded data of a portion onwhich the error detection positions in units of bits cross each other,when the error detection positions obtained by the forward and backwarddecoders cross each other in units of bits but do not cross each otherin units of syntax, and

(d) selecting a position where a crossing portion becomes largest as anerror detection position,

using a forward decode result as a decode value for code words up to aposition immediately before the error detection position obtained by thebackward decoder and a backward decode result as a decode value for codewords from a position immediately after the error detection positionobtained by the forward decoder, and discarding encoded data of aportion on which the error detection positions cross each other, whenthe error detection positions obtained by the forward and backwarddecoders cross each other in units of both bits and syntax.

Considering that an error detection position in a variable length codesucceeds considerably away from the actual error position, in the case(a) in which the error detection positions do not cross each other inboth the forward and backward directions, code words up to a positionset by retracting the encoded data by a predetermined amount from eacherror detection position are used. In the cases (b) to (d) in which theerror detection positions in the forward or backward direction crosseach other somehow, a portion having a large crossing range is discardedto effectively prevent an incorrect portion from being erroneouslydetermined as a correct portion.

Furthermore, according to the present invention, there is provided avideo decoding apparatus comprising an input unit for receiving encodeddata of a video signal containing a variable length code generated byencoding transform coefficients obtained by orthogonal transformation ofthe video signal by using code words that can be decoded in both aforward direction and a backward direction, a sync section detectionunit for detecting a sync section of the encoded data, a forward decoderfor decoding encoded data in the forward direction in a predeterminedsync section detected by the sync section detection unit, a backwarddecoder for decoding encoded data in the backward direction in apredetermined sync section detected by the sync section detection unit,and a decode value determination unit for outputting a final decoderesult from decode results obtained by the forward and backwarddecoders, wherein each of the forward and backward decoders includes anerror detection unit for detecting an error in the encoded data, and thedecode value determination unit determines a decode value by using errordetection positions in the decoded data in units of bits and syntaxwhich indicate an error position in the encoded data which is detectedby the forward decoder, and error detection positions in the decodeddata in units of bits and syntax which indicate an error position in theencoded data which is detected by the backward decoder.

In general, owing to the characteristics of a video encoding scheme, todetermine an incorrect portion as a correct portion influences thedisplay frame more than to discard a correct portion. Therefore, byperforming a double check based on error detection positions in units ofbits and syntax, the influences exerted in the display frame when anincorrect portion is determined as a correction can be greatly reduced.

The decode value determination unit in this video decoding apparatuspreferably uses a decode value determination method of,

(a) using a forward decode result as a decode value for macroblocks upto a position a predetermined amount before the error detection positionin units of bit or syntax, which is obtained by the forward decoder, anda backward decode result as a decode value for macroblocks from aposition a predetermined amount after the error detection position inunits of bits or syntax, which is obtained by the backward decoder, anddiscarding encoded data composed of transform coefficients of theremaining macroblocks, when the error detection positions obtained bythe forward and backward decoders do not cross each other as bothpositions in units of bits and syntax,

(b) using a forward decode result as a decode value for macroblocks upto a position immediately before the error detection position in unitsof syntax, which is obtained by the backward decoder, and a backwarddecode result as a decode value for macroblocks from a positionimmediately after the error detection position in units of syntax, whichis obtained by the forward decoder, and discarding encoded data composedof transform coefficients of a macroblock on which the error detectionpositions in units of syntax cross each other, when the error detectionpositions obtained by the forward and backward decoders do not crosseach other as positions in units of bits but cross each other aspositions in units of syntax,

(c) using a forward decode result as a decode value for macroblocks upto a position immediately before the error detection position in unitsof bits, which is obtained by the backward decoder, and a backwarddecode result as a decode value for macroblocks from a positionimmediately after the error detection position in units of bits, whichis obtained by the forward decoder, and discarding encoded data composedof transform coefficients of a macroblock on which the error detectionpositions in units of bits cross each other, when the error detectionpositions obtained by the forward and backward decoders cross each otheras positions in units of bits but do not cross each other as positionsin units of syntax, and

(d) selecting a position where a crossing portion becomes largest as anerror detection position,

using a forward decode result as a decode value for macroblocks up to aposition immediately before the error detection position obtained by thebackward decoder and a backward decode result as a decode value formacroblocks from a position immediately after the error detectionposition obtained by the forward decoder, and discarding encoded datacomposed of transform coefficients of a macroblock on which the errordetection positions cross each other, when the error detection positionsobtained by the forward and backward decoders cross each other as bothpositions in units of bits and syntax.

Considering that an error detection position in a variable length codesucceeds considerably away from the actual error position, in the case(a) in which the error detection positions do not cross each other inboth the forward and backward directions, macroblocks up to a positionset by retracting the encoded data by a predetermined amount from eacherror detection position are used. In the cases (b) to (d) in which theerror detection positions in the forward or backward direction crosseach other somehow, a portion having a large crossing range is discardedto prevent the influences of determination of an incorrect portion as acorrect portion in the display frame.

When an error is detected in the encoded data in the sync section, thedecode value determination unit discards part or all of encoded datacomposed of macroblock transform coefficients having undergoneintraframe encoding within a macroblock in which no error has beendetected.

In the intraframe encoding mode, the occurrence of an error greatlyinfluences a frame. More specifically, display of wrong coefficientscauses a phenomenon in which a block in unnatural color appears in aframe. If, therefore, at least the occurrence of an error in a syncsection is known, the influences of the error on the frame can bereduced by discarding macroblocks in the intraframe encoding mode.

In addition, the decode value determination unit displays a previousframe for a macroblock from which encoded data is discarded or processesthe macroblock in a mode without encoding when an intraframe encodingmode is set, and performs motion compensation when an interframeprediction encoding mode is set.

In the intraframe encoding mode, when a DCT coefficient is discarded,since no motion vector is present, a previous frame is displayed, ordata is processed in a mode without encoding. In the interframe encodingmode, since a motion vector on the upper layer is present, aconsiderably natural image can be generated by performing motioncompensation using this vector without any DCT coefficient. That is, aDCT coefficient belongs to the lower layer, and a motion vector belongsto the upper layer. If, therefore, an upper motion vector is available,an image can be generated without using any lower DCT coefficient.

Furthermore, according to the present invention, there is provided avariable-length decoding apparatus comprising an input unit forreceiving encoded data formed from a variable length code made up ofcode words including code words that can be decoded in both a forwarddirection and a backward direction, a forward decoder for decoding theencoded data in the forward direction, a backward decoder for decodingthe encoded data in the backward direction, and a decode valuedetermination unit for outputting a final decode result from decoderesults respectively obtained by the forward decoder and the backwarddecoder, wherein each of the forward and backward decoders includes adetection unit for detecting an error in the encoded data, and thedecode value determination unit estimates a range in which an error ispresent on the basis of error detection positions detected in theencoded data by the forward and backward decoders, an error rate in atransmission system or storage system, an occurrence probability of eachcode word, and a bit pattern of each code word in a code word table,thereby determining a final decode value.

In this variable-length decoding apparatus, the probability that anincorrect code word is erroneously decoded as a correct code word can bedecreased to a predetermined probability or less by estimating theactual positions of errors from error detection positions in terms ofprobability in accordance with the error rate in the transmission systemor storage system and the performance of code words.

BRIEF DESCRIPTION OF DRAWINGS

FIG. 1 is a view for explaining a first method of forming the code wordsof a reversible code.

FIGS. 2A and 2B are views respectively showing a forward code tree and abackward code tree.

FIG. 3 is a view for explaining a second method of forming the codewords of a reversible code.

FIG. 4 is a view for explaining a third method of forming the code wordsof a reversible code.

FIG. 5 is a block diagram showing the arrangement of anencoding/decoding system using a variable-length encoding apparatusaccording to the first embodiment of the present invention.

FIGS. 6A and 6B are views showing a syntax for the encoded data used bythe variable-length decoding apparatus according to the firstembodiment.

FIGS. 7A and 7B are views for explaining the principle of a first decodevalue determination method in the variable-length decoding apparatusaccording to the first embodiment.

FIGS. 8A and 8B are views for explaining the principle of a seconddecode value determination method in the variable-length decodingapparatus according to the first embodiment.

FIG. 9 is a flow chart for explaining a procedure for a decode valuedetermination method in the variable-length decoding apparatus accordingto the first embodiment.

FIG. 10 is a block diagram showing the arrangement of a videoencoding/decoding system using a video decoding apparatus according tothe second embodiment of the present invention.

FIG. 11 is a block diagram showing the arrangement of the videodemultiplexer of the video decoding apparatus according to the secondembodiment.

FIGS. 12A and 12B are views showing a syntax for the encoded data usedin the video decoding apparatus according to the second embodiment.

FIG. 13 is a block diagram showing the arrangement of a lower layervariable-length decoding apparatus arranged in the video decodingapparatus according to the second embodiment.

FIG. 14 is a block diagram showing the arrangement of a data sourcedecoder arranged in the video decoding apparatus according to the secondembodiment.

FIGS. 15A and 15B are views for explaining the principle of a firstdecode value determination method in the video decoder according to thesecond embodiment.

FIGS. 16A and 16B are views for explaining the principle of a seconddecode value determination method in the video decoding apparatusaccording to the second embodiment.

FIG. 17 is a view for explaining the principle of a third decode valuedetermination method in the video decoding apparatus according to thesecond embodiment.

FIG. 18 is a flow chart for explaining a procedure for a decode valuedetermination method in the video decoding apparatus according to thesecond embodiment.

FIG. 19 is a flow chart for explaining a procedure by which the encoderof the video ending/decoding system variable-length-encodes the DCTcoefficients of a video signal by using a reversible code.

FIG. 20 is a flow chart for explaining a procedure by which the forwarddecoder of the video encoding/decoding system variable-length-decodesencoded data containing a reversible code.

FIG. 21 is flow chart for explaining a procedure by which the backwarddecoder of the video encoding/decoding system variable-length-decodesencoded data containing a reversible code.

FIG. 22 is a view showing an INDEX table used to search a code wordtable for an INDEX value with RUN and LEVEL values of a non-LASTcoefficient in the INTRA mode in the encoder of the videoencoding/decoding system in FIG. 10.

FIG. 23 is a view showing an INDEX table used to search the code wordtable for an INDEX value with RUN and LEVEL values of a non-LASTcoefficient in the INTER mode in the encoder of the videoencoding/decoding system in FIG. 10.

FIG. 24 is a view showing an INDEX table used to search the code wordtable for an INDEX value with RUN and LEVEL values of a LAST coefficientin the encoder of the video encoding/decoding system in FIG. 10.

FIG. 25 is a view showing a part of the code word table used in thevideo encoding/decoding system in FIG. 10.

FIG. 26 is a view showing the remaining part of the code word table usedin the video encoding/decoding system in FIG. 10.

FIG. 27 is a view showing a RUN fixed-length code word table used in thevideo encoding/decoding system in FIG. 10.

FIG. 28 is a view showing a LEVEL fixed-length code word table used inthe video encoding/decoding system in FIG. 10.

FIG. 29 is a view showing the data format of a fixed-length reversiblecode used in the video encoding/decoding system in FIG. 10.

FIG. 30 is a view showing a part of the code word table used in thevideo encoding/decoding system in FIG. 10.

FIG. 31 is a view showing the remaining part of the code word table usedin the video encoding/decoding system in FIG. 10.

FIG. 32 is a flow chart showing a procedure for a method of detecting anerror in accordance with the occurrence of a bit pattern that is notused for a code word in the video decoding apparatus according to thesecond embodiment.

FIG. 33 is a flow chart showing a procedure for a method of detecting anerror in accordance with the occurrence of a state that cannot exist inunits of syntax in the video decoding apparatus according to the secondembodiment.

FIG. 34 is a view showing another arrangement of the LEVEL fixed-lengthcode word table.

FIG. 35 is a view showing another format of an encoded data sequencehaving ESCAPE codes added to its two ends.

FIG. 36 is a view showing still another format of an encoded datasequence having ESCAPE codes added to its two ends.

FIG. 37 is a flow chart showing a procedure for encode processing in theuse of the encoded data sequence in FIG. 35 or 36.

FIG. 38 is a flow chart showing a procedure for encode processing in theuse of the encoded data sequence in FIG. 35 or 36.

FIG. 39 is a flow chart showing a procedure for decode processing in theuse of the encoded data sequence in FIG. 35 or 36.

FIG. 40 is a flow chart showing an error detection procedure used whenthe encoded data sequence in FIG. 35 or 36 is used.

FIG. 41 is a view showing an arrangement of a LEVEL fixed-length codeword table using a two's-complement expression.

FIG. 42 is a view showing an arrangement of an encoded data sequence inthe use of the LEVEL fixed-length code word table in FIG. 41.

FIG. 43 is a view showing another arrangement of the encoded datasequence in the use of the LEVEL fixed-length code word table in FIG.41.

FIG. 44 is a view showing still another arrangement of the encoded datasequence.

FIG. 45 is a view showing still another arrangement of the encoded datasequence in the use of the LEVEL fixed-length code word table in FIG.41.

FIG. 46 is a view showing still another arrangement of the encoded datasequence in the use of the LEVEL fixed-length code word table in FIG.41.

FIG. 47 is a flow chart showing a procedure for forward decodeprocessing used when the encoded data sequence in FIG. 42, 43, or 46 isused.

FIG. 48 is a flow chart showing a procedure for backward decodeprocessing used when the encoded data sequence in FIG. 42, 43, or 46 isused.

FIG. 49 is a flow chart showing a procedure for forward decodeprocessing used when the encoded data sequence in FIG. 45 is used.

FIG. 50 is a flow chart showing a procedure for backward decodeprocessing used when the encoded data sequence in FIG. 45 is used.

FIG. 51 is a block diagram showing the arrangement of a variable-lengthdecoding apparatus according to the third embodiment of the presentinvention.

FIG. 52 is a view showing a code that does not satisfy the Kraftinequality with an equal sign.

FIG. 53 is a view showing a code tree for a code that does not satisfythe Kraft inequality with an equal sign.

FIG. 54 is a view for explaining a two-dimensional symmetricalcommunication channel.

FIG. 55 is an example of a state transition diagram of code words on thetwo-dimensional symmetrical communication channel.

FIG. 56 is a state transition table of the code words on thetwo-dimensional symmetrical communication channel.

FIGS. 57A, 57B, and 57C are views showing the decoding operation of adecode value determination unit in the third embodiment.

FIGS. 58A, 58B, and 58C are views showing another decoding operation ofthe decode value determination unit in the third embodiment.

FIG. 59 is a view showing a system in which the variable-length decodingapparatus of the present invention is incorporated.

BEST MODE OF CARRYING OUT THE INVENTION

The embodiments of the present invention will be described below withreference to the accompanying drawings.

In the present invention, as variable length codes, reversible codes(Reversible VLCs), which can be decoded in the two directions, i.e., theforward and backward directions, are used. Reversible codes willtherefore be described with reference to FIGS. 1 to 4 prior to adescription of the embodiments of the present invention.

FIG. 1 shows a first method of forming the code words of a reversiblecode. First of all, as indicated on the left side of FIG. 1, two typesof binary sequences having different weights (having 0 and 1 weight inthis case), arranged in the increasing order of code lengths, andrespectively having constant weights (the number of “1”s in this case)are prepared. As indicated by the middle portion of FIG. 1, “1”s areadded to the beginning and end of each of these binary sequences, andthe binary sequences with the weight 1 are inverted. Thereafter, thesetwo types of binary sequences are synthesized, as indicated on the rightside of FIG. 1.

The code length of this variable length code can be known by countingthe number of the symbols at the beginning of the respective codes. Inthe case shown in FIG. 1, if the first symbol is “0”, the appearance ofthree “0”s indicates the boundary (code length) of a code. If the firstsymbol is “1”, the appearance of two “1“s indicates the boundary of acode. The code words of the variable length code in FIG. 1 whichcorrespond to information symbols A to J can be assigned to the leavesof the forward code tree shown in FIG. 2A and the leaves of the backwardcode tree in FIG. 2B. As is obvious, therefore, this code can be decodedin both the forward and backward directions.

FIG. 3 shows a second method of forming the code words of a reversiblecode. First of all, as indicated on the left side of FIG. 3, first andsecond reversible codes are prepared. As indicated by the middle portionof FIG. 3, the first code word of the second reversible code is added tothe end of every code word of the first reversible code. Likewise, everycode word of the second reversible code is added one by one to the endof every code word of the first reversible code. Thereafter, asindicated on the right side of FIG. 3, the resultant code is rearrangedinto a new reversible code. With this forming method, a new reversiblecode having a code word count A×B (27 in this case), i.e., the productof a code word count A (A=9 in this case) of the first reversible codeand a code word count B (B=3 in this case) of the second reversiblecode, can be formed.

When the reversible code formed by this forming method is to be decodedin the forward direction, the first reversible code is decoded first,and then the second reversible code is decoded. When this code is to bedecoded in the backward direction, the second reversible code is decodedfirst, and then the first reversible code is decoded. Obviously, thecode can be decoded in both the forward and backward directions.

In this case, the second reversible code is added to the end of eachcode word of the first reversible code. However, the second reversiblecode may be added to the beginning of the first reversible code orfixed-length codes may be added to both the end and beginning of thefirst reversible code. In addition, although different codes are used asthe first and second reversible codes in this case, identical codes maybe used. Furthermore, in this embodiment, variable length codes are usedas the first and second reversible codes, either of the codes may bereplaced with a fixed-length code.

FIG. 4 shows a third method of forming a reversible code. First of all,as indicated on the left side of FIG. 4, a variable length reversiblecode and a fixed-length reversible code are prepared. As indicated onthe right side of FIG. 4, the fixed-length reversible code is addedimmediately after each bit of the code words of the reversible code.With this forming method, when a K-bit fixed-length reversible code isused, an H-bit code word is formed to have (K+1)H bits, and the codeword count can be increased by 2 KH times.

In this case, the fixed-length code is added immediately after each bitof the code words of the reversible code. However, the fixed-length codemay be added immediately before each bit, or may be added bothimmediately before and after each bit.

Variable-length encoding/decoding apparatuses according the embodimentsof the present invention will be described next.

First Embodiment

FIG. 5 shows the arrangement of a variable-length encoding/decodingapparatus according to an embodiment of the present invention. Thisvariable-length encoding/decoding apparatus generatesvariable-length-encoded data and decodes it. A sync code is periodicallyinserted in variable-length-encoded data. As a variable length code, areversible code (Reversible VLC) that can be decoded in the twodirections, i.e., the forward and backward directions, like thosedescribed above, is used.

As shown in FIG. 5, a variable-length encoding apparatus 11 isconstituted by an encoder 111, a coded word table 112, and a syncsection setting unit 113. The coded word table 112 stores variablelength code words prepared in correspondence with information symbols inaccordance with the reversible code word forming methods described withreference to FIGS. 1 to 4. The coded word table 112 also storesreversible codes, which can be decoded in both the forward and backwarddirections, in correspondence with the respective information symbols.The encoder 111 encodes an information symbol into a variable lengthcode word by referring to the coded word table 112. The encoder 111 thenselects and outputs a code word corresponding to the input informationsymbol from the code words stored in the coded word table 112. The syncsection setting unit 113 combines the code words selected by the encoder111 in each sync section, inserts a stuffing code that can be decoded inboth the forward and backward directions, and outputs encoded data ineach sync section. This encoded data is sent to a variable-lengthdecoder 12 through a transmission system or storage system 13.

The variable-length decoder 12 is constituted by a sync section detector121, a buffer 122, two switches S and T, a forward decoder 123, aforward code word table 124, a decode value determination unit 125, abackward decoder 126, and a backward code word table 127.

In the variable-length decoder 12, the sync sections of the encoded datainput from the transmission system or storage system 13 are detected bythe sync section detector 106, and the encoded data is decoded in eachof the detected sync sections.

If the encoded data input from the transmission system or storage system13 is a variable length code that can be decoded in only the forwarddirection, the switch S is connected to the A side. As a result, theforward decoder 123 performs normal forward decoding by using theforward code word table 124. The encoded data decoded by the forwarddecoder 123 is sent to the decode value determination unit 125.

If the encoded data is a variable-length code that can be decodedbidirectionally, the switch S is connected to the B side. As a result,all the encoded data within a sync section are temporarily stored in thebuffer 122. The total number of bits of the encoded data formed from avariable length code that can be decoded bidirectionally is checked bycounting the number of bits of the encoded data stored in the buffer 122using the forward decoder 123 or the like. Thereafter, the encoded datais read out from the buffer 122, and normal forward decoding is startedby the forward decoder 123 using the forward code word table 124. Theforward decoder 123 performs this forward decoding operation whilechecking whether there is an error in the encoded data.

More specifically, when a bit pattern that cannot exist in the forwardcode word table 124 appears, or data to be decoded runs out before thetotal bit length of decoded encoded data reaches the total number ofbits described above, or a state that is impossible in units of syntax(the rules of grammar for encoded data) has occurred, the forwarddecoder 123 detects that an error has occurred at the position wheresuch a case is detected. The state that is impossible in units of syntaxindicates, for example, a state in which when the number of code wordscontained in each encoded data corresponding to a lower layer isdesignated by encoded data on an upper layer, the designated number ofcode words does not coincide with the number of code words contained ineach encoded data.

The error detection position in units of bits and the error detectionposition in units of syntax are sent as information indicating thedetection position of the error to the decode value determination unit125, together with the result obtained by normally completing forwarddecoding before the detection of the error, regardless of the conditionunder which the encoded data error is detected. In this case, the errordetection position in units of bits indicates the specific bit number ofthe encoded data counted from the start of synchronization as the errordetection position. The error detection position in units of syntaxindicates, for example, the specific code word number of the encodeddata counted from the start of synchronization as the position where theidentical error is detected.

If an error is detected by the forward decoder 123, the switch T isturned on to send the encoded data stored in the buffer 122 to thebackward decoder 126. The backward decoder 126 then starts decoding thedata by using the backward code word table 127. This backward decodingis also performed while the presence/absence of an error in the decodederror is checked. Error detection is performed under the same conditionas that in the case of the forward decoder 123. If an error is detectedin backward decoding, the error detection position in units of bits andthe error detection position in units of syntax are sent as informationindicating the error detection position to the decode valuedetermination unit 125, together with the result obtained by normallycompleting backward decoding before the detection of the error.

The decode value determination unit 125 determines the final decoderesult on the basis of the decode results obtained by the forwarddecoder 123 and the backward decoder 126. That is, the boundary betweena correct code word and an incorrect code word is doubly checked on thebasis of both the error detection positions in units of bits and syntax,which are respectively notified from the forward decoder 123 and thebackward decoder 126. With this operation, the forward decode result andthe backward decode result are selectively used as a decode value foronly a code word that is assumed to be a correct code word with aconsiderably high probability, and the remaining code words arediscarded.

FIGS. 6A and 6B show an example of a syntax for encoded data in thisembodiment.

As shown in FIG. 6A, encoded data is divided into two informationlayers, namely D information on the upper layer and G information on thelower layer. Encoding is performed such that m G code words are presentfor each D code word. If D information is composed of n code words, Ginformation following the D information is composed of n×m code words.In this case, sync intersections are set in units of combinations of Dinformation and succeeding G information, and a resync marker (RM1) isinserted between the sync sections. In addition, a resync marker (RM2)is set between D information and G information.

D information is encoded with a variable length code that can be decodedin only the forward direction. G information is decoded with a variablelength code that can be decoded bidirectionally. As is obvious from thissyntax, the total number of code words of G information can be found outto be n×m when D information is decoded. This total code word count of Ginformation is used to indicate an error detection position as aposition in units of syntax, i.e., to determine which code word amongthe code words, belonging to an interval from the synchronization startposition to the end position, has occurred an error.

FIGS. 7 and 8 show the operation of the decode value determination unit304 in decoding the encoded data of G information formed from areversible variable length code.

First of all, the following functions are defined for G information:

-   -   L: total number of bits    -   W: total number of code words (=n×m)    -   W1: number of code words decoded in forward direction    -   W2: number of code words decoded in backward direction    -   L1: number of bits decoded in forward direction    -   L2: number of bits decoded in backward direction    -   f_code(L1): number of code words obtained when L1 bits are        decoded in forward direction    -   b_code(L2): number of code words obtained when L2 bits are        decoded in backward direction

FIG. 7A shows a case wherein the error detection positions respectivelyobtained by the forward decoder 123 and the backward decoder 126 do notcross each other (i.e., do not pass each other) as both positions inunits of bits and code words, i.e., a case wherein L1+L2<L and W1+W2<W.In this case, encoded data up to a position T code words before eacherror detection position is used. That is, W1−T code words in theforward direction and W2−T code words in the backward direction areused, and the remaining code words are discarded.

In this case, the encoded data is retraced by T code words. However, Ginformation may be retraced by T bits or T blocks.

FIG. 7B shows a case wherein the error detection positions respectivelyobtained by the forward decoder 123 and the backward decoder 126 do notcross each other as positions in units of bits but cross each other aspositions in terms of code words, i.e., a case wherein L1+L2<L andW1+W2≧W. Such a state occurs, for example, when each code word containedin encoded data is decoded as a code word having a bit pattern with abit count smaller than the actual bit count for a while from theposition where an error is actually mixed.

In this case, W−W2 code words in the forward direction and W−W1 codewords in the backward direction are used, and the remaining code wordsare discarded.

FIG. 7A shows a case wherein the error detection positions respectivelyobtained by the forward decoder 123 and the backward decoder 126 crosseach other as positions in units of bits, but do not cross each other aspositions in terms of code words, i.e., a case wherein L1+L2≧L andW1+W2<W. Such a state occurs, for example, when each code word containedin encoded data is decoded as a code word having a bit pattern with abit count larger than the actual bit count for a while from the positionwhere an error is actually mixed.

In this case, the code words of W−b_code(L2) macroblocks in the forwarddirection and the code words of W−f_code(L1) macroblocks in the backwarddirection are used, and the remaining code words are discarded.

FIG. 7B shows a case wherein the error detection positions respectivelyobtained by the forward decoder 123 and the backward decoder 126 crosseach other as both positions in units of bits and code words, i.e., acase wherein L1+L2≧L and W1+W2≧W. In this case, min{W−b_code(L2), W−W2}code words in the forward direction and min{W−f_code(L1), W−W1} codewords in the backward direction are used, and the remaining code wordsare discarded.

In this case, since the total number of code words of G information isfound by using the syntax in FIG. 2, a code word position is used as aposition in units of syntax. However, the present invention can beapplied to any case as long as logical positions obtained by using asyntax are used.

A procedure for a decoding method performed by the variable-lengthdecoder 12 in this embodiment will be described next.

This decoding method is basically performed as follows. As describedwith reference to FIG. 5, encoded data using reversible variable lengthcode words is decoded in the forward direction until an error isdetected in the encoded data. When an error is detected in this forwarddecoding, backward decoding is performed until an error is detected inthe encoded data. A decode value is then determined by using the forwardand backward decode results and error detection positions in units ofbits of encoded data and syntax which are respectively detected in theforward and backward decoding.

FIG. 9 is a flow chart showing a procedure for the method of decodingvariable-length data formed from a reversible code.

First of all, the previously described functions L, W, W1, W2, L1, L2,f_code(L1), and b_code(L2) are defined, and forward decoding is startedfrom first G information in a sync section (step S101). If no error isdetected in this forward decoding within the sync section, the decodeprocessing is terminated (step S102). If an error is detected in theforward decoding, backward decoding is started from last G informationin the sync section (step S103). In general, if an error is detected inthe forward decode processing, an error is normally detected in thebackward decode processing.

If error detection positions do not cross each other as both positionsin units of bits and positions in terms of code words, i.e., a casewherein L1+L2<L and W1+W2<W (step S104), the encoded data up to aposition T code words before each error detection position is used. Thatis, W1−T code words in the forward direction and W2−T code words in thebackward direction are used, and the remaining code words are discarded(step S105).

If the error detection positions do not cross each other as positions inunits of bits but cross each other as positions in terms of code words,i.e., a case wherein L1+L2<L and W1+W1≧W (step S106), W−W2 code words inthe forward direction and W−W1 code words in the backward direction areused, and the remaining code words are discarded (step S107).

If the error detection positions cross each other as positions in unitsof bits but do not cross each other as positions in terms of code words,i.e., a case wherein L1+L2≧L and W1+W2<W (step S108), W−b_code(L2)macroblocks in the forward direction and W−f_code(L1) macroblocks in thebackward direction are used, and the remaining code words are discarded(step S109).

In a case other than those described above, i.e., a case wherein theerror detection positions cross each other as both positions in units ofbits and positions in terms of code words, i.e., a case wherein L1+L2≧Land W1+W2≧W, min{W−b_code(L2), W−W2} code words in the forward directionand min{W−f_code(L1), W−W1} code words in the backward direction areused, and the remaining code words are discarded (step S110).

Second Embodiment

FIG. 10 shows the arrangement of a variable-length encoding/decodingapparatus for video signals according to the second embodiment of thepresent invention.

This video encoding/decoding apparatus is made up of a video encoder 21,a video decoder 22, and a transmission system or storage system 23.

In the video encoder 21, the data encoded by a data source encoder 202is divided into upper layer data and lower layer data by a videomultiplexer 203, and the respective data are variable-length encoded.These upper and lower layer data are multiplexed, and sync sectionsetting and the like are performed. The resultant data is smoothed by atransmission buffer 204. The resultant data is then sent as encoded datato the transmission system or storage system 23. An encoding controlunit 201 controls the data source encoder 202 and the video multiplexer203 in consideration of the buffer amount of the transmission buffer204.

In the video decoder 22, the encoded data from the transmission systemor storage system 23 is stored in a receiving buffer 205, and theencoded data is demultiplexed into upper and lower layer data in unitsof sync sections by a video demultiplexer 206. These data arevariable-length-decoded. The resultant data are sent to a data sourcedecoder 207. Finally, the video data are decoded.

In this case, the variable-length encoding/decoding apparatus describedin the first embodiment is applied to the video multiplexer 203 and thevideo demultiplexer 206.

FIG. 11 is a block diagram showing the video demultiplexer 206 in thesecond embodiment.

The encoded data received by the receiving buffer 205 is sent to ademultiplexer 501, in which sync sections are detected, and the encodeddata is demultiplexed into upper and lower layer data in units of syncsections. The resultant data are respectively sent to an upper layervariable-length decoder 502 and a lower layer variable-length decoder503 to be variable-length-decoded.

FIGS. 12A and 12B show a syntax for encoded video data used in thesecond embodiment.

Encoded data is hierarchically arranged into upper layer data (FIG. 12A)and lower layer data (FIG. 12B) in units of video packets. Sync sectionsare respectively set in upper and lower layer data with a resync marker(RM) and a motion marker (MM). In addition, “ST” on the lower layerrepresents a stuffing code.

According to this syntax, part of the mode information and vectorinformation of a macroblock as a unit in prediction encoding of a videosignal belong to the upper layer, whereas part of the mode information,INTRA DC (the DC value of a DCT coefficient in intraframe encoding), andDCT coefficient information belong to the lower layer. In addition, synccodes indicating boundaries are set in the respective information. Asthe DCT coefficient information, a reversible code is used.

A video packet normally includes a plurality of macroblocks. The numberof the first macroblocks contained in the video packet is set in headerinformation on the upper layer. In addition, mode information 1 andmotion vector information on the upper layer are set in units ofmacroblocks. The number of loops of mode information 1 and motion vectorinformation corresponds to the number of macroblocks contained in thevideo packet.

FIG. 13 is a block diagram showing the arrangement of the lower layervariable-length decoder 503 in the second embodiment.

As described above, of the data demultiplexed into the upper and lowerlayer encoded data in units of sync sections by the demultiplexer 501 inFIG. 1, the lower layer encoded data is sent to the lower layervariable-length decoder 503.

In this lower layer variable-length decoder 503, until DCT coefficientinformation is detected in units of syntax, a switch S is connected tothe A side, and a forward decoder 704 performs normal forward decodingby using a forward code word table 703. The encoded data decoded by theforward decoder 704 is sent to a decode value determination unit 705. Ifan error is detected, the decoded data is compared with the decoderesult obtained by the upper layer variable-length decoder 502 todetermine a decode result.

If the encoded data is DCT coefficient information, the switch S isconnected to the B side, and all the DCT coefficient information in async section is stored in a buffer 702. For example, the forward decoder704 or the like counts the number of bits of the encoded data stored inthe buffer 702 to check the total number of bits of the DCT coefficientinformation formed from a reversible variable length code. Thereafter,the encoded data is read out from the buffer 702, and the forwarddecoder 704 starts normal forward decoding by using the forward codeword table 703. The forward decoder 704 performs forward decoding whilechecking whether there is an error in the encoded data.

More specifically, for example, when a bit pattern that cannot exist inthe forward code word table 703 appears, or data to be decoded runs outbefore the total number of bit lengths of decoded encoded data reachesthe total number of bits described above, or a state that is impossiblein units of syntax occurs, the forward decoder 704 detects that an errorhas occurred at the corresponding detection position. The state that isimpossible in units of syntax indicates, for example, a state whereinthe sum of the run of zeros and number of nonzero coefficients in eachblock of 8×8 DCT coefficients is larger than 64.

The error detection position in units of bits and the error detectionposition in units of syntax are sent as information indicating thedetection position of the error to the decode value determination unit705, together with the result obtained by normally completing forwarddecoding before the detection of the error, regardless of the conditionunder which the encoded data error is detected. In this case, the errordetection position in units of bits indicates the specific bit number ofthe encoded data counted from the start of synchronization of the DCTcoefficient information as the error detection position. The errordetection position in units of syntax indicates the specific macroblocknumber counted from the start of synchronization as the position wherethe identical error is detected.

When an error is detected by the forward decoder 704, a switch T isturned on to send the encoded data stored in the buffer 122 to abackward decoder 708. The backward decoder 708 starts backward decodingby using a backward code word table 707. The backward decoder 708performs this backward decoding while checking whether there is an errorin the encoded data formed from reversible DCT coefficient information.Error detection is performed under the same condition as in the case ofthe forward decoder 704. If an error is detected in the backwarddecoding, the error detection position in units of bits and the errordetection position in units of syntax are sent as information indicatingthe position where the error is detected to the decode valuedetermination unit 705, together with the result obtained by normallycompleting decoding before the detection of the error.

The decode value determination unit 705 determines a final decode resultby comparing the decode result obtained by the forward decoder 704 withthe decode result obtained by the backward decoder 708. That is, theboundary between a correct macroblock and an incorrect macroblock isdoubly checked on the basis of both the error detection positions inunits of bits and syntax, which are respectively notified from theforward decoder 704 and the backward decoder 708. With this operation,the forward decode result and the backward decode result are selectivelyused as a decode value for only a macroblock in which all the code wordsare assumed to be correct with a considerably high probability, and theremaining macroblocks are discarded.

FIG. 14 shows an example of the arrangement of the data source decoder207.

The data source decoder 207 receives the mode information, the motionvector information, the DCT coefficient information, and the like whichare demultiplexed by the video demultiplexer 206 andvariable-length-decoded.

If the mode information is INTRA, a mode determination circuit 804, towhich the mode information is input, turns off a mode switch 805 to bedisconnected from a frame memory 806. The DCT coefficient information isthen dequantized by a dequantizer 801 and is subjected to inversediscrete cosine transform in an IDCT circuit 802. As a result, areconstruction image signal is generated. This reconstruction imagesignal is stored as a reference image in the frame memory 806 and isoutput as a reproduction image signal to a display unit.

If the mode information is INTER, the mode switch 805 is turned on toconnect an adder 803 to the frame memory 806. With this operation, theDCT coefficient information is dequantized by the dequantizer 801 and issubjected to inverse discrete cosine transform in the IDCT circuit 802.The adder 803 adds the resultant data to the information obtained bymotion compensation for the reference image in the frame memory 806 onthe basis of the motion vector information to generate a reconstructionimage signal. This reconstruction image signal is stored as a referenceimage in the frame memory 806 and is also output as a reproduction imagesignal.

FIGS. 15A to 16B show the operation of the decode value determinationunit 705 which is to be performed when the encoded data of DCTcoefficient information formed from a reversible variable length code isto be decoded.

First of all, the following functions for the DCT coefficientinformation are defined:

-   -   L: total number of bits    -   N: total number of macroblocks    -   N1: number of macroblocks decoded in forward direction    -   N2: number of macroblocks decoded in backward direction    -   L1: number of bits decoded in forward direction    -   L2: number of bits decoded in backward direction    -   f_mb(L): number of macroblocks obtained when L bits are decoded        in forward direction    -   b_mb(L): number of macroblocks obtained when L bits are decoded        in backward direction

FIG. 15A shows a case wherein the error detection positions respectivelyobtained by the forward decoder 704 and the backward decoder 708 do notcross each other as both positions in units of bits and positions inunits of macroblocks, i.e., a case wherein L1+L2<L and N1+N2<N. In thiscase, assume that bits to a position retraced by T bits are used, thecoefficient information of f_mb(L1−T) macroblocks in the forwarddirection and the coefficient information of b_mb(L2−T) macroblocks inthe backward direction are used, and the remaining coefficientinformation is discarded.

In this case, the DCT coefficient information is retraced by T bits.However, this information may be retraced by T code words, T blocks, orT macroblocks.

FIG. 15B shows a case wherein the error detection positions respectivelyobtained by the forward decoder 704 and the backward decoder 708 do notcross each other as positions in units of bits but cross each other aspositions in units of macroblocks, i.e., a case wherein L1+L2<L andN1+N2≧N. In this case, the coefficient information of N−N2−1 macroblocksin the forward direction and the coefficient information of N−N1−1macroblock in the backward direction are used, and the remainingcoefficient information is discarded.

FIG. 16A shows a case wherein the error detection positions respectivelyobtained by the forward decoder 704 and the backward decoder 708 crosseach other as positions in units of bits but do not cross each other aspositions in units of macroblocks, i.e., a case wherein L1+L2≧L andN1+N2<N. In this case, the coefficient information of N−b_mb(L2)macroblocks in the forward direction and the coefficient information ofN−f_mb(L1) macroblocks in the backward direction are used, and theremaining coefficient information is discarded.

FIG. 16B shows a case wherein the error detection positions respectivelyobtained by the forward decoder 704 and the backward decoder 708 crosseach other as both positions in units of bits and positions in units ofmacroblocks, i.e., a case wherein L1+L2≧L and N1+N2≧N. In this case, thecoefficient information of min{N−b_mb(L2), N−N2−1} macroblocks in theforward direction and the coefficient information of min{N−f_mb(L1),N−N1−1} macroblocks in the backward direction are used, and theremaining coefficient information is discarded.

In this case, with regard to the macroblocks from which DCT coefficientsare discarded, in the INTRA mode, a previous frame is displayed withoutany change, or processing as a mode without encoding is performed. Inthe INTER mode, a decode value is determined to display the informationwith motion compensation (MC) by using upper layer motion vector (MV)information.

When any one of the states shown in FIGS. 15A, 15B, 16A, and 16B occurs,as shown in FIG. 17, the DCT coefficients of some or all of themacroblocks in the INTRA mode within the corresponding sync section arediscarded, and a previous frame corresponding to the discardedinformation may be displayed or processing as a mode without encoding isperformed, even if no error is detected. In the INTRA mode, an errorgreatly affects a frame. More specifically, when a wrong coefficient isdisplayed, a block in an unnatural color appears in the frame. If,therefore, at least the presence of an error in a sync section is knownin advance, the influence of the error on the frame can be reduced bydiscarding the macroblocks in the INTRA mode.

In the second embodiment, DCT coefficients are discarded in units ofmacroblocks. Obviously, however, this operation may be performed inunits of blocks.

A procedure for the decoding method performed by the lower layervariable-length decoder 503 in the second embodiment will be describednext.

This decoding method is basically performed as follows. As shown in FIG.13, DCT coefficient information formed from reversible variable lengthcode words is decoded in the forward direction until an error isdetected in the information. When an error is detected in this forwarddecoding, backward decoding is performed until an error is detected inthe DCT coefficient information. A decode value is then determined byusing the forward and backward decode results and error detectionpositions in units of bits of encoded data and syntax which arerespectively detected in the forward and backward decoding.

A procedure for decoding the DCT coefficient portion of an AC componentwill be described below with reference to the flow chart of FIG. 18.

First of all, the previously described functions L, N, N1, N2, L1, L2,f_mb(L), and b_mb(L) are defined. Forward decode processing is thenstarted (step S201). If no error is detected in this forward decodeprocessing, the decode processing is terminated (step S202). If an erroris detected in the forward decode processing, backward decoding isstarted (step S203). If an error is detected in the forward decodeprocessing, an error is normally detected in backward decode processing.

If the error detection positions do not cross each other as bothpositions in units of bits and positions in units of macroblocks, i.e.,L1+L2<L and N1+N2<N (step S204), the bits up to a position retraced by Tbits are used. That is, the coefficient information of f_mb(L1−T)macroblocks in the forward direction and the coefficient information ofb_mb(L2−T) macroblocks in the backward direction are used, and theremaining coefficient information is discarded (step S205).

If the error detection positions do not cross each other as positions inunits of bits but cross each other as positions in units of macroblocks,i.e., L1+L2<L and N1+N2≧N (step S206), the coefficient information ofN−N2−1 macroblocks in the forward direction and the coefficientinformation of N−N1−1 macroblocks in the backward direction are used,and the remaining coefficient information is discarded (step S207).

If the error detection positions cross each other as positions in unitsof bits but do not cross each other as positions in units ofmacroblocks, i.e., L1+L2≧L and N1+N2<N (step S208), the coefficientinformation of N−b mb(L2) macroblocks in the forward direction and thecoefficient information of N−f_mb(L1) macroblocks in the backwarddirection are used, and remaining coefficient information is discarded(step S209).

If the error detection positions correspond to another case, and morespecifically, if the error detection positions cross each other as bothpositions in units of bits and positions in units of macroblocks, i.e.,L1+L2≧L and N1+N2≧N, the coefficients of min{N−b_mb(L2), N−N2−1}macroblocks in the forward direction and the coefficients ofmin{N−f_mb(L1), N−N1−1} macroblocks in the backward direction are used,and the remaining coefficients are discarded (step S210).

If an error is detected, the DCT coefficients of all the macroblocks inthe INTRA mode within the corresponding sync section are discarded, anda previous frame is displayed without any change or processing as a modewithout encoding is performed (step S211).

With regard to the macroblocks from which the DCT coefficients arediscarded, in the INTRA mode, a previous frame is displayed without anychange, or processing as a mode without encoding is performed. In theINTER mode, a decode value is determined to display the information withmotion compensation (MC) by using upper layer motion vector (MV)information (step S212).

A detailed arrangement of a code word table used in the videoencoding/decoding apparatus of the second embodiment andencoding/decoding of a reversible code using the table will be describednext.

The data source encoder 202 in FIG. 10 performs intra-block scanning inunits of 8×8 DCT coefficient blocks after quantization to obtain LAST(0: a non-last nonzero coefficient in a block, 1: the last nonzerocoefficient in the block), RUN (the run of zeros up to a nonzerocoefficient), and LEVEL (the quantized value of a coefficient), andsends them to the video multiplexer 203.

The video multiplexer 203 includes an upper layer variable-lengthencoder and a lower layer variable-length encoder. The code word tableof the lower layer variable-length encoder for performingvariable-length encoding using a reversible code includes the fourtables shown in FIGS. 22 to 26. FIG. 22 shows an INDEX table forsearching the code word tables in FIGS. 25 and 26 for an INDEX valuewith RUN and LEVEL of a non-LAST coefficient for INTRA (intraframeencoding). FIG. 23 shows an INDEX table for searching the code wordtables in FIGS. 25 and 26 for an INDEX value with RUN and LEVEL of anon-LAST coefficient for INTER (interframe encoding). FIG. 24 shows anINDEX table for searching the code word tables in FIGS. 25 and 26 for anINDEX value with RUN and LEVEL of a LAST coefficient common to INTRA andINTER. FIGS. 25 and 26 show code word tables in which INDEX values aremade to correspond to reversible variable length code words (VLC-CODE).In addition, as tables for conversion to fixed-length reversible codewords, the RUN fixed-length code word table shown in FIG. 27 and theLEVEL fixed-length code word table shown in FIG. 28 are used.

A procedure for variable-length encode processing performed by the lowerlayer variable-length encoder using these tables will be described belowwith reference to the flow chart of FIG. 19.

First of all, INDEX tables to be used are selected in accordance withthe prediction mode designated by upper layer mode information (stepS301). In this case, if the prediction mode is INTRA, the INDEX tablesshown in FIGS. 22 and 24 are selected. If the prediction mode is INTER,the INDEX tables shown in FIGS. 23 and 24 are selected.

It is then checked whether the RUN and LEVEL values of the DCTcoefficient to be encoded are not more than the maximum RUN and LEVELvalues defined in the INDEX tables to be used (step S302). If the RUNand LEVEL values are not more than the maximum RUN and LEVEL valuesdefined in the INDEX tables, the RUN and LEVEL values are used to searchthe INDEX tables to obtain an INDEX value for searching the code wordtables shown in FIGS. 25 and 26 (step S303). It is checked whether theINDEX value obtained from the INDEX tables is “0” (step S304). If thisvalue is not “0”, the code word tables in FIGS. 25 and 26 are searchedto output a reversible code word corresponding to the INDEX value (stepS305). The last bit “s” of each reversible code word in the code wordtables in FIGS. 25 and 26 represents the sign of LEVEL. When “s” is “0”,the sign of LEVEL is positive. When Is” is “1”, the sign of LEVEL isnegative.

If the RUN and LEVEL values to be encoded exceed the maximum RUN andLEVEL values defined in the INDEX tables to be used, or the INDEX valueobtained from the INDEX tables is “0”, (LAST, RUN, and LEVEL) arefixed-length are encoded into fixed-length codes. ESCAPE codes are thenadded to each code at its two ends, and the resultant codes are output(step S306). More specifically, the RUN and LEVEL values arerespectively converted into 6- and 7-bit fixed-length codes by using theRUN fixed-length code word table in FIG. 27 and the LEVEL fixed-lengthcode word table in FIG. 28, and one bit corresponding to the LAST valueis added to the beginning of each of these fixed-length codes, as shownin FIG. 29. In addition, ESCAPE codes are added to the two ends of eachcode sequence. The ESCAPE code at the beginning is “00001”, and theESCAPE code at the end is a reversible code “0000s” to be searched outwith INDEX value=“0” in the code word tables in FIGS. 25 and 26. Thelast bit “s” of this reversible code “0000s” indicates the sign ofLEVEL. When “s” is “0”, the sign of LEVEL is positive. When “s” is “1”,the sign of LEVEL is negative.

A reversible code decoding method performed by the forward decoder 704and the backward decoder 708 will be described next.

In the forward code word table 703 and the backward code word table 707,decode value tables like those shown in FIGS. 30 and 31 are prepared ascode word tables, in addition to the code word tables in FIGS. 25 and26, the RUN fixed-length code word table in FIG. 27, and the LEVELfixed-length code word table in FIG. 28. In the decode value tables inFIGS. 30 and 31, decode values for (LAST, RUN, and LEVEL) correspondingto the INDEX values in the INTRA and INTER modes are set.

Forward decode processing will be described first with reference to theflow chart of FIG. 20.

First of all, decode processing for encoded data is performed, and anINDEX value corresponding to the reversible code word is obtained byusing the code word tables shown in FIGS. 25 and 26 (step S401). It isthen checked whether the INDEX value is “0” (step S402). If this valueis not “0”, the decode value tables in FIGS. 30 and 31 are searched withthe INDEX value and the mode to obtain decode values of (LAST, RUN, andLEVEL) which correspond to the used prediction mode and INDEX value(step S403). If the INDEX value is “0”, since it indicates an ESCAPEcode, the succeeding fixed-length codes of (LAST, RUN, and LEVEL) aredecoded by using the fixed-length code word tables in FIGS. 27 and 28(step S404). The ESCAPE code at the end is decoded (step S405). The signof LEVEL is determined by using the last one bit of each code word (stepS406).

Backward decode processing will be described next with reference to theflow chart of FIG. 21.

First of all, the sign of LEVEL is determined on the basis of the firstone bit of the code word (step S501). An INDEX value corresponding tothe reversible code word is obtained by using the code word tables shownin FIGS. 25 and 26 (step S502). It is then checked whether the INDEXvalue is “0” (step S503). If this value is not “0”, the decode valuetables in FIGS. 30 and 31 are searched with the INDEX value and theprediction mode to obtain decode values of (LAST, RUN, and LEVEL) whichcorrespond to the used prediction mode and INDEX value (step S504). Ifthe INDEX value is “0”, since it indicates an ESCAPE code, thesucceeding fixed-length codes of (LAST, RUN, and LEVEL) are decoded byusing the fixed-length code word tables in FIGS. 27 and 28 (step S505).The ESCAPE code at the beginning is then decoded (step S506).

A procedure for error detection processing performed in each of forwarddecode processing and backward decode processing in the secondembodiment will be described next.

FIG. 32 is a flow chart for detecting an error depending on whether abit pattern that cannot exist in the forward code word table 124 appearsin encoded data.

First of all, in order to check whether a corresponding code word ispresent in the code word table used in forward or backward decodeprocessing, it is checked whether the INDEX value obtained by the abovedecode processing for the encoded data is present (step S601). If theINDEX value is not present, it is determined that a code word patternthat cannot exist in the table has appeared, thereby detecting an error(step S606).

If the INDEX value is present in the table, it is checked whether theINDEX value is “0” (step S602). If the INDEX value is “0”, since itindicates that encoding is performed by using an ESCAPE code, it ischecked whether a combination of (LAST, RUN, LEVEL) is present in thecode word table (step S603). If the combination is present in the codeword table, it is determined that a code word pattern that does exist inthe table has appeared, thereby detecting an error (step S606). If thecombination of (LAST, RUN, LEVEL) is not present in the code word table,it is checked whether an ESCAPE code is present at the end of thefixed-length code (step S604). If no ESCAPE code is present, it isdetermined that a code word pattern that cannot exist in the table hasappeared, thereby detecting an error (step S606). If the ESCAPE code ispresent, it is determined that the pattern is a correct encoded bitpattern, and proper decode processing is performed (step S605).

When the INDEX value is present in the code word table and the INDEXvalue is not 0, the code bit pattern is determined as a correct code bitpattern, and decode processing is properly performed (step S605).

FIG. 33 is a flow chart for detecting an error depending on whether astate that is impossible in units of syntax has occurred. In this case,it is checked in units of 8×8 DCT coefficient blocks whether the sum ofthe run of zeros and number of nonzero coefficients is larger than 64.

First of all, it is checked whether a DC component in 8×8 DCTcoefficients is contained in the encoded data of the DCT coefficientportion of an AC component (step S701). If the DC component iscontained, “0” is set as an initial value in a variable SUM representingthe sum of the run of zeros and number of nonzero coefficients (stepS702). If the component is not contained, “1” is set as an initial valuein the variable SUM (step S703).

Subsequently, variable-length decoding of the encoded data of each DCTcoefficient given by (LAST, RUN, and LEVEL) is repeatedly executed untilLAST=1” (steps S704 to S707). In this processing, every timevariable-length decoding of (LAST, RUN, LEVEL) is performed in stepS704, the value obtained by adding one to the RUN value representing therun of zeros up to a nonzero coefficient, i.e., the value of RUN+1 isadded to the variable SUM (step S705). The reason why the RUN value isincremented by one is that one coefficient is decoded regardless ofwhether it is a zero or nonzero coefficient. It is then checked whetherthe value of the variable SUM is larger than 64 (step S706). If thevalue of the variable SUM is larger than 64, the occurrence of a syntaxerror is detected (step S709).

If no syntax error is detected until the LAST coefficient becomes “1”,the decoding processing for this block is normally terminated (stepS708).

(Another Format Having ESCAPE Codes Added to Two Ends of Code Sequence)

FIGS. 34 and 35 show another format having ESCAPE codes added to the twoends of a code sequence. The RUN and LEVEL values are respectivelyconverted into 6- and 11-bit fixed-length codes by using the RUNfixed-length code word table in FIG. 23 and the LEVEL fixed-length codeword table in FIG. 34. At this time, Marker Bits “1” are set at the twoends of LEVEL to limit the run of zeros. As shown in FIG. 35, one bitcorresponding to a LAST value is added to the beginning of this codesequence. In addition, ESCAPE codes are added to the two ends of thecode sequence. The ESCAPE code at the beginning is “100001”, and theESCAPE code at the end is the reversible code “0000s” that is searchedout with INDEX value=“0” in the code word tables in FIGS. 25 and 26. Thelast bit “s” of this reversible code “0000s” represents the sign ofLEVEL. When “s” is “0”, the size of LEVEL is positive. When “s” is “1”,the sign of LEVEL is negative.

FIG. 37 shows a procedure for lower layer variable-length encodeprocessing which corresponds to FIG. 19.

Steps S801 to S805 are the same as steps S301 to S305 in FIG. 19. Thisprocedure differs from that in FIG. 19 in step S806. In this case,Marker Bits are set at the two ends of LEVEL.

FIGS. 38 and 39 show reversible code decoding methods respectivelyperformed by the forward decoder 704 and the backward decoder 708.

Steps S901, S902, S903, S905, and S906 in the forward decode processingin FIG. 38 are the same as steps S401, S402, S403, S405, and S406constituting the forward decode processing in FIG. 20. This processingdiffers from that in FIG. 20 in step S904. In step S904, thefixed-length codes of (LAST, RUN, LEVEL) following an ESCAPE code andMarker Bit are decoded as well as the fixed-length codes of (LAST, RUN,LEVEL) following the ESCAPE code.

Similarly, steps S1001, S1002, S1003, S1005, and S1006 are the same assteps S501, S502, S504, S505, and S506 constituting the backward decodeprocessing in FIG. 21. This procedure differs from that in FIG. 21 instep S1005. In this case, the fixed-length codes of (LEVEL, RUN, LAST)and Marker Bit are decoded as well as the fixed-length codes of (LEVEL,RUN, LAST).

In this case, as a format having ESCAPE codes added to the two ends of acode sequence, the format in which RUN consists of 6 bits and LEVELconsists of either 7 or 11 bits is exemplified. The numbers of bits arenot limited to these.

FIG. 36 shows another format having ESCAPE codes added to the two endsof a code sequence. If, for example, the fixed-length code of LEVEL islong and exceeds the zero run limit, Marker Bit is preferably insertedbetween the fixed-length codes of LEVELs, as shown in FIG. 36. If, forexample, the code length of a sync code such as a resync marker is 17bits (zero run of 16 bits+1: “00000000000000001”), the run of zeros islimited not more than 15 bits to avoid confusion between the sync wordand other code words. In this case, if the fixed-length code of LEVEL islong, and the run of zeros may exceed 16 bits, Marker Bit is insertedbetween the fixed-length codes of LEVELs, as shown in FIG. 36. This canavoid confusion between the fixed-length code of LEVEL and a sync wordeven if the fixed-length code length is long.

FIG. 40 is a flow chart showing a method of detecting a code wordpattern in which no AC-DCT portion exists. This flow chart correspondsto FIG. 32.

To check whether the code word is present in a code word table, it ischecked whether an INDEX value is present (step S1101). If the INDEXvalue is not present, a code word pattern that cannot exist has occurred(step S1107).

If the INDEX value is present, it is checked whether the INDEX value is0 (step S1102). If the INDEX is 0, it indicates that encoding isperformed by using an ESCAPE code. In this case, a combination of (LAST,RUN, and LEVEL) is decoded to check whether the combination is presentin the code word table (step S1103). If the combination is present inthe code word table, a code word pattern that cannot exist has occurred(step S1107).

It is also checked whether Maker Bit is correct (step S1104). If MarkerBit is not correct, a code word pattern that cannot exist has occurred(step S1107).

If the INDEX value is not 0, it indicates that decoding has beenproperly performed (step S1106).

If Maker Bit is correct in the case of the combination that cannot existin the code word table, it is checked whether an ESCAPE code is presentat the end of the fixed-length code (step S1105). If no ESCAPE code ispresent, a code word pattern that cannot exist has occurred (stepS1107). If an ESCAPE code is present, it indicates that decoding hasbeen properly performed (step S1106).

As described above, in this case, the processing of determining whetherMarker Bit is correct is added to error detection processing performedin each of forward decode processing and backward decode processing.

(Still Another Format Having ESCAPE Codes Added to Two Ends of CodeSequence)

FIGS. 41 and 42 show still another format having ESCAPE codes added tothe two ends of a code sequence. Assume that a LEVEL value is expressedin a two's-complement form. In this case, since the sign of LEVEL isspecified by a code word of LEVEL, an ESCAPE code at the end of the codesequence is “00001”, and the code “s” representing the sign of LEVEL isnot used.

RUN and LEVEL values are respectively converted into fixed-length codesby using the RUN fixed-length code word table in FIG. 27 and the LEVELfixed-length code word table in FIG. 41. At this time, Marker Bits “1”are set at the two ends of LEVEL to limit the run of zeros. As shown inFIG. 42, one bit corresponding to a LAST value is added to the beginningof this code sequence. In addition, ESCAPE codes are added to the twoends of the code sequence.

The insertion of Marker Bit between the end of LEVEL and the ESCAPE codecan be omitted depending on the fixed code length of LEVEL. FIG. 43shows an example of this case. FIG. 43 shows a case wherein the fixedcode length of LEVEL is 12 bits.

The run of zeros of LEVEL is (fixed code length of LEVEL-2) bits. If,therefore, the fixed code length of LEVEL is 13 bits or less, even ifthe run of zeros of the ESCAPE code at the end, which is 4 bits, isadded to the fixed code length, the sum of runs of zeros is smaller thanthe limit value (16 bits) set for a 16-bit sync code.

In addition, since the zero run limit is determined by the number ofbits of a sync code as described above, if the code length of a synccode is set to be long, the insertion of Marker Bit can be omittedregardless of whether an absolute value or a two's-complement number isused as a code word of LEVEL, as shown in FIGS. 44 and 45.

In contrast to this, even if a code word of LEVEL is expressed in atwo's-complement form, Marker Bit may be inserted in the code of LEVELso as not to exceed the zero run limit in the same manner as in FIG. 36.FIG. 46 shows an example of this case.

FIG. 47 shows a case wherein a code word of LEVEL is expressed in atwo's-complement form, and Marker Bit is inserted in the code word,i.e., a procedure for forward decode processing to be performed when theencoded data sequence shown in FIG. 42, 43, or 46 is used.

This processing differs from the forward decode processing in FIG. 38 inwhich an absolute value is used as a code word of LEVEL in that stepS906 is omitted. More specifically, when a code word of LEVEL isexpressed in a two's-complement form, the sign of LEVEL is alsodetermined in decode processing for the fixed-length codes of (LAST,RUN, and LEVEL) and Marker Bit in step S204.

FIG. 48 shows a case wherein a code word of LEVEL is expressed in atwo's-complement from, and Marker Bit is inserted in the code word,i.e., a procedure for backward decode processing to be performed whenthe encoded data sequence shown in FIG. 42, 43, or 46 is used.

This processing differs from the backward decode processing (FIG. 39)using an absolute value as a code word of LEVEL in that step S1301 isomitted. More specifically, when a code word of LEVEL is expressed in atwo's-complement form, the sign of LEVEL is also determined in decodeprocessing for the fixed-length codes of (LEVEL, RUN, LAST) and MarkerBit in step S1304.

FIG. 49 shows a case wherein a code word of LEVEL is expressed in atwo's-complement form, and Marker Bit is not used, i.e., a procedure forforward decode processing to be performed when the encoded data sequencein FIG. 45 is used. This processing differs from that in FIG. 47 in thatonly the fixed-length codes of (LAST, RUN, LEVEL) are decoded in stepS1204.

FIG. 50 shows a case wherein a code word of LEVEL is expressed in atwo's-complement form, and Marker Bit is not used, i.e., a procedure forbackward decode processing to be performed when the encoded datasequence in FIG. 45 is used. This processing differs from that in FIG.48 in that only the fixed-length codes of (LEVEL, RUN, LAST) are decodedin step S1505.

Third Embodiment

An error range estimating method which can be applied to decode valuedetermination processing in the first and second embodiments will bedescribed as the third embodiment of the present invention.

FIG. 51 is a block diagram showing the arrangement of a variable-lengthdecoder 109 according to the third embodiment of the present invention.

The variable-length decoder 109 is designed to decode encoded datacontaining variable length codes in units of sync sections as in thefirst and second embodiments, and has the same basic arrangement as thatof the first and second embodiments.

In the variable-length decoder 109, when encoded data is a variablelength code that can be decoded only in the forward direction, a switchS is connected to A, and normal forward decoding is performed by aforward decoder 104. The encoded data decoded by the forward decoder 104is sent to a decode value determination unit 105.

When the encoded data is a reversible variable length code that can bedecoded in both the forward and backward directions, the switch 101 isconnected to B, and the encoded data is stored in a buffer 102. Afterthe total number of bits of the encoded data is checked, the data isdecoded by the forward decoder 104.

If an error is detected by the forward decoder 104, a switch 106 isturned on, and the encoded data stored in the buffer 102 is decoded by abackward decoder 108 in the backward direction.

In the forward decoder 104 and the backward decoder 108, when, forexample, a code that cannot exist appears, it is determined that anerror has occurred.

The decode value determination unit 105 determines a final decode resulton the basis of a combination of the decode results respectivelyobtained by the forward decoder 104 and the backward decoder 108.

The operation of the decode value determination unit 105 for the encodeddata of a reversible variable length code will be described below.

In the third embodiment, a final decode value is determined byestimating an error range from the encoded data error detectionpositions detected in forward and backward decode processing, the errorrate in the transmission system or storage system, the occurrenceprobability of each code word, and the bit pattern of each code word ina code word table. In the first and second embodiments, a rangepreceding an error detection position by a predetermined amount (T codewords) is specified as an error propagation range in a fixed manner. Incontrast to this, in the third embodiment, an optimal value of T isobtained by estimating an error propagation range.

It is known that the code length of a Huffman code obtained by optimalencoding of a memoryless information source satisfies the followingKraft inequality with an equal sign if the code is two-dimensional.

$\begin{matrix}{{\sum\limits_{x \in X}^{\;}\; 2^{- {l{(X)}}}} = 1} & (1)\end{matrix}$where x is a code word of a code X, and 1(x) is the code length of x.

When sync sections are set, and sync codes are inserted as in thepresent invention, since design is made to prevent a collision with async code pattern (e.g., 000, . . . , 01), a code that does not satisfythe Kraft inequality with an equal sign is used.

$\begin{matrix}{{\sum\limits_{x \in X}^{\;}\; 2^{- {l{(X)}}}} < 1} & (2)\end{matrix}$

In codes like those shown in FIGS. 56, 57A, 57B, and 57C, “0000” isdesignated as a forbidden code word to prevent a collision with a synccode. In such a code, when a variable length code cannot be properlydecoded upon mixing of an error, and the pattern “0000” that cannotexist appears, the occurrence of an error can be detected.

In a communication channel model of the transmission system or storagesystem for transmitting or storing encoded data, if a two-dimensionalsymmetrical communication channel with an error rate ε (0<ε<1) as shownin FIG. 58 is assumed, a conditional probability P_((y|P(y|x)x)) oftransmission of a code word x and reception of a reception sequence ycan be given as follows, without consideration of bit insertion andloss.

$\begin{matrix}{P_{({y|x})} = \left\{ \begin{matrix}{ɛ^{d{({x,y})}}\left( {1 - ɛ} \right)}^{{l{(x)}} - {d{({x,y})}}} & {{l(x)} = {l(y)}} \\0 & {{l(x)} \neq {l(y)}}\end{matrix} \right.} & (3)\end{matrix}$where d(x,y) is the Hamming distance between the sequence x and thesequence y.

Consequently, a probability P(y) of reception of the sequence y is givenby

$\begin{matrix}{{P(y)} = {\sum\limits_{x \in X}^{\;}\;{{P(x)}{P\left( y \middle| x \right)}}}} & (4)\end{matrix}$Assume that the number of code words of the code X is finite, and P(x)>0for all code words x.

However, in order to analyze the state between the instant at which abit stream is input and the instant at which an error is detected, astate (initial state I) in which at least a 1-bit error is included mustbe considered.

Since the probability that the code word x does not include even a 1-biterror is given by (1−ε)^(1(x)), the conditional probability that eachcode word includes at least 1 1-bit error can be given by

$\begin{matrix}\begin{matrix}{{P^{\prime}\left( y \middle| x \right)} = \left\{ \begin{matrix}\frac{P\left( y \middle| x \right)}{1 - \left( {1 - ɛ} \right)^{l{(x)}}} & {{d\left( {x,y} \right)} \neq 0} \\0 & {{d\left( {x,y} \right)} = 0}\end{matrix} \right.} \\{\mspace{155mu}{{P^{\prime}(y)} = {\sum\limits_{x \in X}^{\;}\;{{P(x)}{P^{\prime}\left( y \middle| x \right)}}}}}\end{matrix} & (5)\end{matrix}$

Consider a target code that can be instantaneously decoded. In thiscase, the reception sequence y without any error starts from the root ofa code tree and always reaches a leaf portion of the code tree.

In the presence of an error, however, the reception sequence y may startor may be received in the state of a node as well as a leaf portion ofthe code tree, and hence can be expressed by a state transition diagramlike that of FIG. 55. Since a transition probability t_(ij) to eachstate is given by

$\begin{matrix}{t_{ij} = \left\{ \begin{matrix}{\sum\limits_{y \in Y}^{\;}\;{{P^{\prime}(y)}{V\left( {y,\left. i\rightarrow j \right.} \right)}}} & {i = 1} \\{\sum\limits_{y \in Y}^{\;}\;{{P(y)}{V\left( {y,\left. i\rightarrow j \right.} \right)}}} & {i \geq 2}\end{matrix} \right.} & (6)\end{matrix}$the state transition probability t_(ij) of transition from a state i toa state j can be obtained. In this case, a function V(y, i→j) takes thevalue 1 if the reception sequence y makes a transition from the state ito the state j; otherwise, the value 0.

In this case, the respective states are defined as follows:

I initial state

S synchronous state

U_(i) asynchronous state i=1, . . . , N−2

E error detection state

FIG. 55 shows an example of the state transition diagram of a code word.FIG. 56 shows a code word state transition table.

A matrix T is a portion, of the state transition table, which isobtained by excluding an error detection probability from each state andis defined as

$\begin{matrix}{T = \begin{pmatrix}t_{11} & t_{12} & \cdots & t_{1N} \\\vdots & \vdots & ⋰ & \vdots \\t_{N1} & t_{N2} & \cdots & t_{NN}\end{pmatrix}} & (7)\end{matrix}$Assume that a vector D is the probability of transition from each stateto the error detection state E.D=(t _(1N+1) , t _(2N+1) , . . . , t _(NN+1))^(T)  (8)

Since a transition starts from the initial state I, the initialprobability of each state excluding the error detection state E can begiven byQ(0)=(1, 0, . . . 0)  (9)the probability of each state excluding the error detection state Eafter i code words can be calculated byQ(i)=Q(0)T ^(i−1)  (10)

The probability of detection of an error after i code words is thereforethe probability detected next in each state after i−1 code words, andhence can be expressed asR(i)=Q(i−1)D=Q(0)T ^(i-1) D i=1,2,  (11)where T⁰ is a unit matrix I.

When the estimated probability a is set, the number of code words fromwhich errors can be detected with the set probability can be calculated.

$\begin{matrix}{a < {\sum\limits_{i = 1}^{j}\;{R(i)}}} & (12)\end{matrix}$When F(a) is set by obtaining a minimum value of j, as expressed above,an error range can be estimated in terms of probability. F(a)corresponds to T in the first and second embodiments, as previouslydescribed.

That is, an error is present with the probability a in a range precedingan error detection position by F(a) code words. In addition, from theviewpoint of decode processing, with this value, a portion to which anerror may have propagated can be removed with the probability a byretracing the code by F(a) code words from an error detection position.

The decode value determination unit 105 calculates a range F₁(a) inwhich an error is present in the forward direction and a range F₂(a) inwhich an error is present in the backward direction on the basis of aforward code word table 103, a backward decoder 108, the probabilityP(x) of occurrence of a code word, the error rate ε in the communicationchannel, and the estimated probability a, and determines a portion to bediscarded in accordance with a relationship with the error detectionpositions.

If the error detection position in the forward direction and the errordetection position in the backward direction do not cross each other asshown in FIG. 57A, the range to be discarded is increased by retracingthe encoded data by the ranges F₁(a) and F₂(a) in which the errors arepresent.

If the error detection position in the forward direction and the errordetection position in the backward direction cross each other and thecrossing range is larger than the range in which the errors are present,as shown in FIG. 57B, the crossing range is determined as a range to bediscarded.

If the error detection position in the forward direction and the errordetection position in the backward direction cross each other and thecrossing range is smaller than the error range in which the errors arepresent, as shown in FIG. 57C, the range in which the errors are presentis determined as a range to be discarded.

In addition, an error range can be estimated from the number of bits bymultiplying F(a) by an average code length.

$\begin{matrix}{{B(a)} = {{F(a)}{\sum\limits_{x \in X}^{\;}\;{{P(x)}{l(x)}}}}} & (13)\end{matrix}$

In this case, the decode value determination unit 105 operates in themanner shown in FIG. 58A, 58B, or 58C. If the error detection positionin the forward direction and the error detection position in thebackward direction do not cross each other as shown in FIG. 58A as inthe case shown in FIG. 57A, 57B, or 57C, the range to be discarded isincreased by retracing the encoded data by the ranges B₁(a) and B₂(a) inwhich the errors are present.

If the error detection position in the forward direction and the errordetection position in the backward direction cross each other and thecrossing range is larger than the range in which the errors are present,as shown in FIG. 58B, the crossing range is determined as a range to bediscarded.

If the error detection position in the forward direction and the errordetection position in the backward direction cross each other and thecrossing range is smaller than the error range in which the errors arepresent, as shown in FIG. 58C, the range in which the errors are presentis determined as a range to be discarded.

Although the third embodiment has exemplified the variable-lengthdecoder capable of directional decoding, the present invention can alsobe applied to a variable-length decoder capable of only normal forwarddecoding.

As described above, in the variable-length decoding apparatus of thethird embodiment, decode processing is performed in the followingprocedure: 1) decoding encoded data in the forward direction untildetection of an error in the encoded data, 2) decoding the encoded datain the backward direction upon detection of an error in the encoded datain forward decoding, and 3) estimating a range in which the errors arepresent on the basis of the forward and backward decode results, theencoded data error detection positions respectively detected in theforward and backward decoding, the error rate in the transmission systemor storage system, the occurrence probability of each code word, and thebit pattern of each code word in the code word table, therebydetermining a final decode value.

As described above, the probability that an incorrect code word iserroneously decoded as a correct code word can be decreased to apredetermined probability or less by estimating the actual positions oferrors from error detection positions in terms of probability inaccordance with the error rate in the transmission system or storagesystem and the performance of code words.

Note that the procedures for decode processing performed by thevariable-length decoding apparatuses of the first to third embodimentsdescribed above can be implemented by computer programs stored inrecording media such as a computer readable CD-ROM, DVD-ROM, andDVD-RAM. Even a computer having no dedicated hardware forvariable-length decoding can therefore perform decode processing withlittle influences of errors contained in encoded data. In addition, partor all of the hardware of the variable-length decoding apparatusaccording to each of the first to third embodiments can be mounted, andits operation control can be performed by computer programs.

Fourth Embodiment

An example of a video encoding/decoding system incorporating thevariable-length encoding/decoding apparatus according to each of thefirst to third embodiments of the present invention will be described asan application of the present invention with reference to FIG. 59. Theimage signal input through a camera 1002 mounted on a personal computer(PC) 1001 is encoded by the video encoder or video encoding softwareincorporated in the PC 1001. The encoded data is multiplexed with otherinformation such as speech information and data information. Theresultant data is transmitted from a radio unit 1003 by radio and isreceived by another radio unit 1004. The signal received by the radiounit 1004 is demultiplexed into the encoded data of the image signal andthe speech data. Of these data, the encoded data of the image signal isdecoded by the video decoder or video decoding software incorporated ina workstation (EWS) 1005 and is displayed on the display of the EWS1005.

The image signal input through a camera 1006 mounted on the EWS 1005 isencoded by the video encoder or encoding software incorporated in theEWS 1005 as in the above case. The encoded data is multiplexed withother information such as speech information and data information. Theresultant data is transmitted from the radio unit 1004 by radio and isreceived by the radio unit 1003. The signal received by the radio unit1003 is demultiplexed into the encoded data of the image signal and thespeech information or data information. Of these data, the encoded dataof the image signal is decoded by the video decoder or video decodingsoftware incorporated in the PC 1001 and is displayed on the display ofthe PC 1001.

Note that the video decoding software is implemented by a program forcausing the computer to execute the procedure for variable-length decodeprocessing described in each of the above embodiments.

In addition, the arrangements of the first to third embodiments and theformats of encoded data sequences described above can be used incombination, as needed.

As has been described above, according to the present invention, thereis provided a variable-length decoding apparatus and method, which candecrease the possibility of decoding an incorrect code word as a correctcode word by using error detection positions in encoded data in units ofbits and error detection positions in the encoded data in units ofsyntax, and can reduce the influences of channel errors. In addition,with the application of the variable-length decoding apparatus andmethod of the present invention to video decode processing, theinfluences of channel errors in the display frame can be reduced evenwhen encoded video signals are transmitted through an environmentincluding many channel errors such as a radio communication channel.Furthermore, the probability of decoding an incorrect code word as acorrect code word can be further decreased by estimating an errorpropagation range.

INDUSTRIAL APPLICABILITY

The video decoding apparatus of the present invention described above issuited to decoding variable-length encoded video information or the likethat is encoded into a reversible variable length code decodable in bothforward and backward directions and recorded on a recording medium ortransmitted.

1. A computer system comprising: means for receiving encoded data of avideo signal containing a variable length code generated by encodingtransform coefficients obtained by orthogonal transformation of thevideo signal by using code words decodable in both a forward directionand a backward direction; means for detecting a sync section of theencoded data; means for decoding the encoded data in the forwarddirection in a predetermined sync section detected by the sync sectiondetection unit; means for decoding the encoded data in the backwarddirection in the detected sync section; and means for determining afinal decode result from decode results obtained by the decoding meansin the forward direction and the decoding means in the backwarddirection, wherein each of the decoding means in the forward directionand the decoding means in the backward direction includes means fordetecting an error in the encoded data, and the determining meansincludes means for determining a decode value by using an errordetection position in the encoded data in units of bits and an errordetection position in the decoded data in units of syntax, which aredetected by the decoding means in the forward direction and indicate anerror position in the encoded data, and an error detection position inthe encoded data in units of bits and an error detection position inunits of syntax, which are detected by the decoding means in thebackward direction and indicate an error position in the encoded datawherein when an error is detected in the encoded data in the syncsection, the determining means includes means for discarding part or allof encoded data composed of macroblock transform coefficients havingundergone intraframe encoding within a macroblock in which no error hasbeen detected.
 2. A computer system comprising: means for receivingencoded data of a video signal containing a variable length codegenerated by encoding transform coefficients obtained by orthogonaltransformation of the video signal by using code words decodable in botha forward direction and a backward direction; means for detecting a syncsection of the encoded data; means for decoding the encoded data in theforward direction in the detected sync section; means for decoding theencoded data in the backward direction in the detected sync section; andmeans for determining a final decode result from decode results obtainedby the decoding means in the forward direction and the decoding means inthe backward direction, wherein each of the decoding means in theforward direction and the decoding means in the backward directionincludes means for detecting an error in the encoded data, and thedetermining means includes means for determining a decode value by usingan error detection position in the encoded data in units of bits and anerror detection position in the decoded data in units of syntax, whichare detected by the decoding means in the forward direction and indicatean error position in the encoded data, and an error detection positionin the encoded data in units of bits and an error detection position inunits of syntax, which are detected by the decoding means in thebackward direction and indicate an error position in the encoded data,wherein each encoded data in the sync section includes transformcoefficients of a plurality of macroblocks as a unit in performingprediction encoding for a video signal, and the determining meansincludes, (a) means for using a forward decode result as a decode valuefor macroblocks up to a position a predetermined amount before the errordetection position in units of bits or syntax which is obtained by thedecoding means in the forward direction, and a backward decode result asa decode value for macroblocks from a position a predetermined amountafter the error detection position in units of bits or syntax which isobtained by the decoding means in the backward direction, and discardingencoded data composed of transform coefficients of the remainingmacroblocks, when the error detection positions obtained by the decodingmeans in the forward direction and the decoding means in the backwarddirection do not cross each other as both positions in units of bits andsyntax, (b) means for using a forward decode result as a decode valuefor macroblocks up to a position immediately before the error detectionposition in units of syntax which is obtained by the decoding means inthe backward direction, and a backward decode result as a decode valuefor macroblocks from a position immediately after the error detectionposition in units of syntax which is obtained by the decoding means inthe forward direction, and discarding encoded data composed of transformcoefficients of a macroblock on which the error detection positions inunits of syntax cross each other, when the error detection positionsobtained by the decoding means in the forward direction and the decodingmeans in the backward direction do not cross each other as positions inunits of bits but cross each other as positions in units of syntax, (c)means for using a forward decode result as a decode value formacroblocks up to a position immediately before the error detectionposition in units of bits which is obtained by the decoding means in thebackward direction, and a backward decode result as a decode value formacroblocks from a position immediately after the error detectionposition in units of bits which is obtained by the decoding means in theforward direction, and discarding encoded data composed of transformcoefficients of a macroblock on which the error detection positions inunits of bits cross each other, when the error detection positionsobtained by the decoding means in the forward direction and the decodingmeans in the backward direction cross each other as positions in unitsof bits but do not cross each other as positions in units of syntax, and(d) means for selecting a position where a crossing portion becomeslargest as an error detection position, using a forward decode result asa decode value for macroblocks up to a position immediately before theerror detection position obtained by the decoding means in the backwarddirection and a backward decode result as a decode value for macroblocksfrom a position immediately after the error detection position obtainedby the decoding means in the forward direction, and discarding encodeddata composed of transform coefficients of a macroblock on which theerror detection positions cross each other, when the error detectionpositions obtained by the decoding means in the forward direction andthe decoding means in the backward direction cross each other as bothpositions in units of bits and syntax, wherein when an error is detectedin the encoded data in the sync section, the determining means includesmeans for discarding part or all of encoded data composed of macroblocktransform coefficients having undergone intraframe encoding within amacroblock in which no error has been detected.